#引进封装断言
from api.ihrm_login_api import IhrmLoginApi
from common.assert_tools import common_assert
class TestIhrmLogin(object):
    # 定义 测试方法 - 登录成功
    def test01_login_success(self):
        # 准备登录测试数据
        data = {"mobile": "13800000002", "password": "929itheima.CN032@.20250612"}
        # 调用 自己封装的 api， 获取响应结果
        resp = IhrmLoginApi.login(data)
        # 打印查看
        print("登录成功：", resp.json())
        # 断言
        common_assert(resp, 200, True, 10000, "操作成功")
        # assert 200 == resp.status_code
        # assert True is resp.json().get("success")
        # assert 10000 == resp.json().get("code")
        # assert "操作成功" in resp.json().get("message")

    # 定义 测试方法 - 手机号未注册
    def test02_mobile_not_register(self):
        # 准备登录测试数据
        data = {"mobile": "13874873701", "password": "929itheima.CN032@.20250609"}
        # 调用 自己封装的 api， 获取响应结果
        resp = IhrmLoginApi.login(data)
        # 打印查看
        print("手机号未注册：", resp.json())
        # 断言
        common_assert(resp, 200,False , 20001, "用户名或密码错误")
        # assert 200 == resp.status_code
        # assert False is resp.json().get("success")
        # assert 20001 == resp.json().get("code")
        # assert "用户名或密码错误" in resp.json().get("message")

    # 定义 测试方法 - 密码错误
    def test03_pwd_err(self):
        # 准备登录测试数据
        data = {"mobile": "13800000002", "password": "929itheima.CN032@.20250608"}
        # 调用 自己封装的 api， 获取响应结果
        resp = IhrmLoginApi.login(data)
        # 打印查看
        print("密码错误：", resp.json())
        # 断言
        common_assert(resp, 200, False, 20001, "用户名或密码错误")
        # assert 200 == resp.status_code
        # assert False is resp.json().get("success")
        # assert 20001 == resp.json().get("code")
        # assert "用户名或密码错误" in resp.json().get("message")

    def test04_mobile_is_none(self):
        data = {"mobile": None, "password": "123456"}
        resp = IhrmLoginApi.login(data)
        print("手机号为空：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test05_mobile_have_special_char(self):
        data = {"mobile": "1380abc#002", "password": "123456"}
        resp = IhrmLoginApi.login(data)
        print("手机号含有特殊字符：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test06_10_mobile(self):
        data = {"mobile": "1380000000", "password": "123456"}
        resp = IhrmLoginApi.login(data)
        print("10位手机号：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test07_12_mobile(self):
        data = {"mobile": "138000000034", "password": "123456"}
        resp = IhrmLoginApi.login(data)
        print("12位手机号：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test08_pwd_none(self):
        data = {"mobile": "13800000002", "password": None}
        resp = IhrmLoginApi.login(data)
        print("密码为空：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test09_pwd_have_special_char(self):
        data = {"mobile": "13800000002", "password": "abc#￥%"}
        resp = IhrmLoginApi.login(data)
        print("密码含有特殊字符：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test10_pwd_1(self):
        data = {"mobile": "13800000002", "password": "1"}
        resp = IhrmLoginApi.login(data)
        print("密码1位：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test11_pwd_100(self):
        data = {"mobile": "13800000002","password":"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"}
        resp = IhrmLoginApi.login(data)
        print("密码100位：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test12_more_params(self):
        data = {"mobile": "13800000002", "password": "123456", "abc": "123"}
        resp = IhrmLoginApi.login(data)
        print("多参：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test13_less_params(self):
        data = {"mobile": "13800000002"}
        resp = IhrmLoginApi.login(data)
        print("少参-password：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test14_none_params(self):
        data = None
        resp = IhrmLoginApi.login(data)
        print("无参：", resp.json())
        common_assert(resp, 200, False, 99999, "抱歉，系统繁忙，请稍后重试！")

    def test15_err_parames(self):
        data = {"abc": "13800000002", "password": "123456"}
        resp = IhrmLoginApi.login(data)
        print("错误参数：", resp.json())
        common_assert(resp, 200, False, 20001, "用户名或密码错误")